#pragma once
//============================================================================
// Copyright (C) 2009-2013 Brett R. Jones 
// All Rights Reserved
//
// You may redistribute and/or modify for non commercial and commercial uses 
// provided this copyright notice remains in place and is not modified
//
// This code is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//
// brettjones1900@gmail.com
// http://www.p2panarchy.com
//============================================================================

#include <VxNetLib/VxSktUdpBroadcast.h>
#include <RcSysPktLib/RcSysPktAnnounce.h>

class RcSysSktBroadcast : public VxSktUdpBroadcast
{
public:
	//=== constructor ===//
	RcSysSktBroadcast();
	//=== destructor ===//
    virtual ~RcSysSktBroadcast();

	//! start broadcasting
	RCODE		StartBroadcast( VxInetAddress&		oLclIp,
								RcSysPktAnnounce *  poPktAnn,					// packet announce to send out
								U16					u16Port = 15783,			// port to broadcast on
								U32					u32TimeIntervalSeconds = 4,	// time interval between broadcasts
								const char *		pBroadcastIp = 0);				
	//! stop broadcasting
	void		StopBroadcast( void );

	//! called after PktAnnounce has changed
	void		onPktAnnUpdated( RcSysPktAnnounce& oPktAnn );


	//=== vars ===//
	VxThread			m_oTxThread;					// thread to transmit broadcasts
	U32					m_u32TimeIntervalSeconds;		// interval between broadcasts
	RcSysPktAnnounce    m_oPktAnn;						// announce packet original
	RcSysPktAnnounce    m_oPktAnnEncrypted;				// announce packet encrypted
	int					m_iBroadcastDataLen;			// length of announce packet
	VxKey				m_oRxKeyCopy;
	U16					m_u16UdpPort;
private:
	//! generate broadcast key
	void		generateUdpBroadcastKeys( void );
};
